id-arena
A simple, id-based arena.
Id-based
Allocate objects and get an identifier for that object back, not a reference to the allocated object. Given an id, you can get a shared or exclusive reference to the allocated object from the arena. This id-based approach is useful for constructing mutable graph data structures.
If you want allocation to return a reference, consider the typed-arena
crate instead.
No Deletion
This arena does not support deletion, which makes its implementation simple
and allocation fast. If you want deletion, you need a way to solve the ABA
problem. Consider using the generational-arena
crate instead.
Homogeneous
This crate's arenas can only contain objects of a single type T
. If you
need an arena of objects with heterogeneous types, consider another crate.
#![no_std]
Support
Requires the alloc
nightly feature. Disable the on-by-default "std"
feature:
[]
= "2"
= false
rayon
Support
If the rayon
feature of this crate is activated:
[]
= { = "2", = ["rayon"] }
then you can use rayon
's support for
parallel iteration. The Arena
type will have a par_iter
family of
methods where appropriate.
Example
use ;
type AstNodeId = ;
let mut ast_nodes = new;
// Create the AST for `a * (b + 3)`.
let three = ast_nodes.alloc;
let b = ast_nodes.alloc;
let b_plus_three = ast_nodes.alloc;
let a = ast_nodes.alloc;
let a_times_b_plus_three = ast_nodes.alloc;
// Can use indexing to access allocated nodes.
assert_eq!;